package org.irri.smta.ui.bean;

import javax.faces.bean.SessionScoped;
import javax.faces.model.SelectItem;
import javax.inject.Inject;
import javax.inject.Named;

import org.irri.smta.common.Constants;
import org.irri.smta.util.BeanUtils;
import org.primefaces.event.SelectEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Named("smtaReportHomeBean")
@SessionScoped
public class SmtaReportHomeBean extends SmtaReportBean {

	private static final long serialVersionUID = 1L;
	private static final Logger LOGGER = LoggerFactory
			.getLogger(SmtaReportHomeBean.class);

	@Inject
	@Named("loginBean")
	private LoginBean loginBean = null;
	
	private SelectItem[] yesNoOptions;
	private BeanUtils beanUtils = new BeanUtils();

	public SmtaReportHomeBean() {
		super();
		setViewName(Constants.SMTA_REPORT_HOME_VIEW_NAME);
		this.yesNoOptions = createYesNoOptions();
	}

	public void preRenderView() {
		LOGGER.debug("preRenderView()");
		if (beanUtils.getSessionUser() == null) {
			loginBean.defaultLogin();
		}
		if (!beanUtils.validateUser()) {
			beanUtils.navigateToView(Constants.LOGIN_VIEW_NAME);
		}
	}
	
	@Override
	public void onRowSelect(SelectEvent event)
			throws Exception {
		LOGGER.debug("onRowSelect(SelectEvent event)");
		super.onRowSelect(event);
//		openMaterialView();
	}

	private SelectItem[] createYesNoOptions()  {
		LOGGER.debug("SelectItem[] createYesNoOptions()");
        SelectItem[] options = new SelectItem[3];

		options[0] = new SelectItem("", "All");
		options[1] = new SelectItem("true", "Yes");
        options[2] = new SelectItem("false", "No");

        return options;
	}
	
	public SelectItem[] getYesNoOptions() {
		return this.yesNoOptions;
	}
	
}
